﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace BizAppFactory.Domain
{
    public partial class UniqueConstraint
    {
        public BindingList<BizAppFactory.Domain.Attribute> CollectAllPossibleAttributes()
        {
            BindingList<BizAppFactory.Domain.Attribute> allPossibleAttribute = new BindingList<BizAppFactory.Domain.Attribute>();
            
            //TODO: Value objects that are not connected with 1-1 relationship must be filtered out
            foreach (DomainClass childDomainClass in this.Entity.ChildDomainClasses)
            {
                if (childDomainClass is ValueObject)
                {
                    foreach (BizAppFactory.Domain.Attribute attribute in ((ValueObject)childDomainClass).Attributes)
                    {
                        AddAttributesOrDataTypesAttributes(attribute, allPossibleAttribute);
                    }
                }
            }

            foreach (BizAppFactory.Domain.Attribute attribute in this.Entity.Attributes)
            {
                AddAttributesOrDataTypesAttributes(attribute, allPossibleAttribute);
            }

            return allPossibleAttribute;
        }

        void AddAttributesOrDataTypesAttributes(Attribute attribute, BindingList<BizAppFactory.Domain.Attribute> allPossibleAttribute)
        {
            if (attribute.DomainDataType == null)
            {
                allPossibleAttribute.Add(attribute);
            }
            else
            {
                foreach (BizAppFactory.Domain.Attribute dataTypeAttribute in attribute.DomainDataType.Attributes)
                {
                    allPossibleAttribute.Add(dataTypeAttribute);
                }
            }
        
        }
    }
}